<%@ page import="coop.bancocredicoop.proyectos.gd.DocumentType" %>
<%@ page import="coop.bancocredicoop.proyectos.gd.FileType" %>
<!DOCTYPE html>
<html>
	<head>
		<meta name="layout" content="main">
		<g:set var="entityName" value="${message(code: 'documentType.label', default: 'DocumentType')}" />
		<title><g:message code="default.create.label" args="[entityName]" /></title>
	</head>
	<body>
		
        <div class="container">
        <div class="main-panel">
        <div class="panel panel-default">
        <div class="panel-heading">
            <h2><g:message code="default.create.label" args="[entityName]" default="Crear {0}" />
            </h2>
        </div>			
        <div class="panel-body">

        <g:if test="${flash.message}">
            <g:if test="${flash.success == null || flash.success}">
        <div class="alert alert-success" role="status">${flash.message}</div>
            </g:if>
            <g:else>
        <div class="alert alert-danger" role="status">${flash.message}</div>
            </g:else>
        </g:if>

        <g:hasErrors bean="${documentTypeInstance}">
        <div class="alert alert-danger">
        <ul class="errors" role="alert">
            <g:eachError bean="${documentTypeInstance}" var="error">
            <li><g:message error="${error}"/></li>
            </g:eachError>
        </ul>
        </div>
        </g:hasErrors>

        <g:form class="form-horizontal" role="form" url="[resource:documentTypeInstance, action:'save']" method="POST" >
          
          <g:hiddenField name="version" value="${documentTypeInstance?.version}" />

          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.name.label" default="Nombre" /></label>
            <div class="col-sm-10">

            <input type="text" class="form-control" id="name" name="name" placeholder="Nombre" value="${documentTypeInstance.name}">
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.purgeable.label" default="Purgable" /></label>
            <div class="col-sm-10">
                <div class="radio">
                  <label>
                    <input type="radio" name="purgeable" id="purgeableTrue" value="true" ${documentTypeInstance.purgeable ? 'checked' : ''} >
                    Sí
                  </label>
                </div>
                <div class="radio">
                  <label>
                    <input type="radio" name="purgeable" id="purgeableFalse" value="false" ${documentTypeInstance.purgeable ? '' : 'checked'} >
                    No
                  </label>
                </div>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.hasExpiration.label" default="Tiene vencimiento" /></label>
            <div class="col-sm-10">
                <div class="radio">
                  <label>
                    <input type="radio" name="hasExpiration" id="hasExpirationTrue" value="true" ${documentTypeInstance.hasExpiration ? 'checked' : ''} >
                    Sí
                  </label>
                </div>
                <div class="radio">
                  <label>
                    <input type="radio" name="hasExpiration" id="hasExpirationFalse" value="false" ${documentTypeInstance.hasExpiration ? '' : 'checked'} >
                    No
                  </label>
                </div>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.defaultLastingMonths.label" default="Duración por defecto en meses" /></label>
            <div class="col-sm-10">
              <input type="number" class="form-control" id="defaultLastingMonths" name="defaultLastingMonths" min="1" max="9999" step="1" value="${documentTypeInstance.defaultLastingMonths ?: 12}" /> 
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.daysInAdvanceForNotice.label" default="Días de anticipo para notificación" /></label>
            <div class="col-sm-10">
              <input type="number" class="form-control" id="daysInAdvanceForNotice" min="1" max="1000" step="1" value="${documentTypeInstance.daysInAdvanceForNotice ?: 7}" name="daysInAdvanceForNotice" /> 
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.uploadNotificationEmailAddress.label" default="Correo electrónico para notificación de carga" /></label>
            <div class="col-sm-10">
              <input type="email" class="form-control" id="uploadNotificationEmailAddress" name="uploadNotificationEmailAddress" placeholder="Dirección de correo electrónico" value="${documentTypeInstance.uploadNotificationEmailAddress}">
            </div>
          </div>


          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.versionable.label" default="Versionable" /></label>
            <div class="col-sm-10">
                <div class="radio">
                  <label>
                    <input type="radio" name="versionable" id="versionableTrue" value="true" ${documentTypeInstance.versionable ? 'checked' : ''} >
                    Sí
                  </label>
                </div>
                <div class="radio">
                  <label>
                    <input type="radio" name="versionable" id="versionable" value="false" ${documentTypeInstance.versionable ? '' : 'checked'} >
                    No
                  </label>
                </div>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.fileTypes.label" default="Tipos de carga" /></label>
            <div class="col-sm-10">
              <g:each in="${FileType.list(sort: 'name')}" var="fileType">
                <div class="checkbox">
                <label>
                <g:if test="${documentTypeInstance?.fileTypes?.contains(fileType)}">
			    <input name="fileTypes" type="checkbox" value="${fileType.id}" checked />
                </g:if>
                <g:else>
			    <input name="fileTypes" type="checkbox" value="${fileType.id}" />
                </g:else>
                    ${fileType.encodeAsHTML()}
                </label>
                </div>
			  </g:each>
            </div>
          </div>


          <div class="form-group">
            <label class="col-sm-2 control-label"><g:message code="documentType.shortName.label" default="Nombre archivo" /></label>
            <div class="col-sm-10">
              <input type="text" class="form-control" id="shortName" placeholder="Nombre de archivo" value="${documentTypeInstance.shortName}" name="shortName">
            </div>
          </div>

          <g:actionSubmit class="btn btn-default" action="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />

        </g:form>

        </div>
        </div>
        </div>
        </div>
 
	</body>
</html>